import java.awt.*;
import java.awt.event.*;
import java.lang.Integer;
import javax.swing.*;

public class ATMGui extends JPanel {
	private static JTextField balanceDisplay = new JTextField(10);
	private JButton addFunds = new JButton("Add Funds");
	private JButton withdrawFunds = new JButton("Withdraw Funds");
	private JButton balanceCheck = new JButton("Check Balance");
	private JButton enter = new JButton("Enter");
	private JTextArea input = new JTextArea();
	static ATMFunctions atm = new ATMFunctions();

	public ATMGui() {
		setLayout(new BorderLayout());	
		balanceDisplay.setEditable(false);
		Font font = new Font("Lucida Console", Font.PLAIN, 22);
		balanceDisplay.setFont(font);
		add(input, BorderLayout.NORTH);
		add(balanceDisplay, BorderLayout.CENTER);

		JPanel buttonPanel1 = new JPanel();
		buttonPanel1.setLayout(new GridLayout(1, 4, 0, 0));
		buttonPanel1.add(addFunds);
		buttonPanel1.add(withdrawFunds);
		buttonPanel1.add(balanceCheck);
		buttonPanel1.add(enter);
		
		add(buttonPanel1, BorderLayout.SOUTH);

		addFunds.addActionListener(new addFundsAL());
		withdrawFunds.addActionListener(new withdrawFundsAL());
		balanceCheck.addActionListener(new balanceCheckAL());
		enter.addActionListener(new enterAL());
	}

	public class addFundsAL implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			balanceDisplay.setText("Enter amount to deposit");
			addFunds.setSelected(true);
			input.setText("");
		}
	}

	public class withdrawFundsAL implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			balanceDisplay.setText("Enter amount to withdraw");
			withdrawFunds.setSelected(true);
			input.setText("");
		}
	}

	public class balanceCheckAL implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			atm.printBalance();
			input.setText("");
		}
	}
	
	public class enterAL implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			if (addFunds.isSelected()){
				String amount = input.getText();
				int money = Integer.parseInt(amount);
				atm.addFunds(money);
				addFunds.setSelected(false);
				input.setText("");
			}
			if (withdrawFunds.isSelected()) {
				String amount = input.getText();
				int money = Integer.parseInt(amount);
				atm.withdrawFunds(money);
				withdrawFunds.setSelected(false);
				input.setText("");
			}
		}
	}
	
	public static void updateDisplay(String string){
		balanceDisplay.setText(string);
	}
	
}
